package com.bins.langchain.langchain4j.controller;

import com.bins.langchain.langchain4j.service.ChatService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;


@RestController
@RequestMapping("/qw")
@RequiredArgsConstructor
public class ChatController {

    @Autowired
    private ChatService chatService;

    @GetMapping("/chat")
    public String chat(String prompt) {
        return chatService.generate(prompt);
    }

    @GetMapping("/stream/chat")
    public Flux<String> streamChat(String prompt) {
        return chatService.streamChat(prompt);
    }

    @PostMapping("/embed")
    public String embed(@RequestBody String text) {
        return chatService.embedding(text);
    }

    @PostMapping("/embed-meta")
    public String embedMeta(@RequestBody String text) {
        return chatService.embeddingWithMeta(text);
    }

    @GetMapping("/search")
    public List<String> search(String text) {
        return chatService.search(text);
    }
}